/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GameObject;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.io.File;
import java.io.IOException;
import java.util.Timer;
import javax.imageio.ImageIO;

/**
 *
 * @author NGUYEN VAN TAM
 */
public class Label extends Window{
    @Override
    public boolean Init(int _numberSprite[], int _Width,int _Heigth,String StrResource[],int isprite)
    {
            _nsprite = _numberSprite.length;
            _sprite = new Sprite[_nsprite];
            _textDisplay = null;
            _positionText = null;
            
            for (int i = 0; i < _nsprite; i++)
            {
                try
                {
                    Image[] image = new Image[_numberSprite[i]];

                    for (int j = 0; j < _numberSprite[i]; j++)
                    {
                        image[j] = ImageIO.read(new File(StrResource[i] + j + ".png"));
                    }
                    _sprite[i] = new Sprite(0, 0, _Width,_Heigth ,image);
                    _isprite = isprite;
                }
                catch(IOException ex)
                {
                    return false;
                }
            }
            return true;
    }
    
    @Override
    public VisibleGameObject Clone()
    {
        VisibleGameObject obj = new Label();
        obj._nsprite = this._nsprite;
        obj.x = this.x;
        obj.y = this.y;
        obj._isprite = this._isprite;
        ((Label)obj)._textDisplay = this._textDisplay;
        ((Label)obj)._positionText = this._positionText;
        ((Label)obj)._font = this._font;
        ((Label)obj)._color = this._color;
        
        for(int i = 0;i < this._sprite.length;i++)
        {
            obj._sprite[i] = new Sprite(this.x, this.y, this._sprite[i]._width, this._sprite[i]._height, this._sprite[i]._images);
        }
        return obj;
    }    
    @Override
    public void Update(Timer gameTime,int x, int y, int w, int h)
    {
        if(show == true)
        {
            if(nDelay == 0)
            {
                this.x = x;
                this.y = y;
                this.width = w;
                this.height = h;

                for (int i = 0; i < _sprite.length; i++)
                {
                    _sprite[i].update(gameTime,x,y,w,h,_sprite[i]._selectedIndex);
                }
            }
            else 
            {
                nDelay --;
            }
        }
    }
    
    @Override
    public void Update(Timer gameTime)
    {
        this.Update(gameTime);
    }
    

    @Override
    public void Draw(Timer gameTime,Graphics2D graphic)
    {
        this.Draw(gameTime, graphic);
    }
}